class ForumsController < ApplicationController
  def index
    @forums = Forum.find(:all,:order  => 'position')
    # puts 'in action => index'
    # raise 'acticon index'
  end

  def show
    @forum = Forum.find(params[:id],:include => :topics)
    @topics = @forum.topics.paginate(:all, :page => params[:page], :per_page => @per_page)
    
  end
  
  def new
      @forum  = Forum.new
      if request.xhr?
        render :layout  => false        
      end

  end
  
  def create
    @forum = Forum.new params[:forum]
    respond_to do |wants|
      wants.html { }
      wants.js do
        render :update do |page|
          if @forum.save
            page.alert "saved!"
          else
            # page.alert "errors"
            page.replace_html "new_forum_form", :partial=>"new",:object=>@forum
            #page.alert @forum.errors.to_s
          end
        end
      end
    end
  end
  
  def update_positions
    # y params[:forums_list]
#    raise params[:forums_list]
    params[:forums_list].each_with_index do |id,index|
      # f = Forum.find id
      # f.position = index
      # f.save
      Forum.update(id,:position  => index)
    end
    render :nothing => true
  end
  

end
